package com.wzh.example.serializable;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @Author zh wang
 * @Create 2025/4/27 19:34
 */
public class Test {
    public static void main(String[] args) throws Exception {
        //SerializeObj obj = new SerializeObj();
        //obj.setName("张三Test");
        //obj.setAge(11);
        //System.out.println("obj.getAge() = " + obj.getAge());
        //SerializeObj.num = 2;
        //System.out.println("obj = " + obj);
        //
        //ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("test.dat"));
        //out.writeObject(obj);
        //out.flush();
        //
        //SerializeObj.num = 3;
        //obj.setName("张三Test2");
        //obj.setAge(12);

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("test.dat"));
        SerializeObj obj2 = (SerializeObj) in.readObject();

        System.out.println("obj2 = " + obj2);
        System.out.println("obj2.num = " + obj2.num);

    }
}
